home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWLinShp.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  12.8 KB  |  471 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWLinShp.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWLINSHP_H
  13. #include "FWLinShp.h"
  14. #endif
  15.  
  16. #ifndef FWSHAPE_H
  17. #include "FWShape.h"
  18. #endif
  19.  
  20. #ifndef FWDFAULT_H
  21. #include "FWDfault.h"
  22. #endif
  23.  
  24. #ifndef FWGC_H
  25. #include "FWGC.h"
  26. #endif
  27.  
  28. #ifndef FWINK_H
  29. #include "FWInk.h"
  30. #endif
  31.  
  32. #ifndef FWSTYLE_H
  33. #include "FWStyle.h"
  34. #endif
  35.  
  36. #ifndef FWOVLSHP_H
  37. #include "FWOvlShp.h"
  38. #endif
  39.  
  40. #ifndef FWRRCSHP_H
  41. #include "FWRRcShp.h"
  42. #endif
  43.  
  44. #ifndef FWARCSHP_H
  45. #include "FWArcShp.h"
  46. #endif
  47.  
  48. #ifndef FWRECSHP_H
  49. #include "FWRecShp.h"
  50. #endif
  51.  
  52. #ifndef FWRGNSHP_H
  53. #include "FWRgnShp.h"
  54. #endif
  55.  
  56. #ifndef FWGRUTIL_H
  57. #include "FWGrUtil.h"
  58. #endif
  59.  
  60. // ----- OpenDoc Includes -----
  61.  
  62. #ifndef _TRNSFORM_
  63. #include <Trnsform.h>
  64. #endif
  65.  
  66. //==============================================================================
  67. //    •• RunTime Info
  68. //==============================================================================
  69.  
  70. #ifdef FW_BUILD_MAC
  71. #pragma segment fwgraphx
  72. #endif
  73.  
  74. //==============================================================================
  75. //    •• class FW_CLineShape
  76. //==============================================================================
  77.  
  78. //------------------------------------------------------------------------------
  79. // FW_CLineShape::FW_CLineShape
  80. //------------------------------------------------------------------------------
  81.  
  82. FW_CLineShape::FW_CLineShape() :
  83.     FW_CShape()
  84. {
  85. }
  86.  
  87. //------------------------------------------------------------------------------
  88. // FW_CLineShape::FW_CLineShape
  89. //------------------------------------------------------------------------------
  90.  
  91. FW_CLineShape::FW_CLineShape(const FW_CPoint& start, const FW_CPoint& end) :
  92.     FW_CShape()
  93. {
  94.     SetRep(new FW_CLineShapeRep(start, end));
  95. }
  96.  
  97. //------------------------------------------------------------------------------
  98. // FW_CLineShape::FW_CLineShape
  99. //------------------------------------------------------------------------------
  100.  
  101. FW_CLineShape::FW_CLineShape(const FW_CLineShape& other) :
  102.     FW_CShape(other)
  103. {
  104. }
  105.  
  106. //------------------------------------------------------------------------------
  107. // FW_CLineShape::FW_CLineShape
  108. //------------------------------------------------------------------------------
  109.  
  110. FW_CLineShape::FW_CLineShape(FW_CLineShapeRep* rep) :
  111.     FW_CShape(rep)
  112. {
  113. }
  114.  
  115. //------------------------------------------------------------------------------
  116. // FW_CLineShape::operator=
  117. //------------------------------------------------------------------------------
  118.  
  119. FW_CLineShape& FW_CLineShape::operator=(const FW_CLineShape& other)
  120. {
  121.     SetRep(other.GetRep());
  122.     return *this;
  123. }
  124.  
  125. //------------------------------------------------------------------------------
  126. // FW_CLineShape::operator=
  127. //------------------------------------------------------------------------------
  128.  
  129. FW_CLineShape& FW_CLineShape::operator=(FW_CLineShapeRep* other)
  130. {
  131.     SetRep(other);
  132.     return *this;
  133. }
  134.  
  135. //------------------------------------------------------------------------------
  136. // FW_CLineShape::operator FW_COvalShape
  137. //------------------------------------------------------------------------------
  138.  
  139. FW_CLineShape::operator FW_COvalShape() const
  140. {    
  141.     FW_COvalShape ovalShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
  142.     ovalShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  143.     return ovalShape;
  144. }
  145.  
  146. //------------------------------------------------------------------------------
  147. // FW_CLineShape::operator FW_CRoundRectShape
  148. //------------------------------------------------------------------------------
  149.  
  150. FW_CLineShape::operator FW_CRoundRectShape() const
  151. {    
  152.     FW_CRoundRectShape roundRectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), FW_kZeroPoint);
  153.     roundRectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  154.     return roundRectShape;
  155. }
  156.  
  157. //------------------------------------------------------------------------------
  158. // FW_CLineShape::operator FW_CArcShape
  159. //------------------------------------------------------------------------------
  160.  
  161. FW_CLineShape::operator FW_CArcShape() const
  162. {    
  163.     FW_CArcShape arcShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), 0, 0);
  164.     arcShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  165.     return arcShape;
  166. }
  167.  
  168. //------------------------------------------------------------------------------
  169. // FW_CLineShape::operator FW_CRectShape
  170. //------------------------------------------------------------------------------
  171.  
  172. FW_CLineShape::operator FW_CRectShape() const
  173. {    
  174.     FW_CRectShape rectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
  175.     rectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  176.     return rectShape;
  177. }
  178.  
  179. #ifdef FW_BUILD_MAC
  180. //-------------------------------------------------------------------------
  181. // MakeLineRgn
  182. //-------------------------------------------------------------------------
  183.  
  184. void MakeLineRgn(FW_SPlatformPoint start, FW_SPlatformPoint end, short pen)
  185. {    
  186.     ::MoveTo(start.h, start.v);
  187.     ::LineTo(end.h, end.v);
  188.     ::Line(pen, 0);
  189.     ::Line(0, pen);
  190.     ::LineTo(start.h + pen, start.v + pen);
  191.     ::Line(-pen, 0);
  192.     ::Line(0, -pen);
  193. }
  194. #endif
  195.  
  196. //------------------------------------------------------------------------------
  197. // FW_CLineShape::operator FW_CRegionShape
  198. //------------------------------------------------------------------------------
  199.  
  200. FW_CLineShape::operator FW_CRegionShape() const
  201. {
  202. #ifdef FW_BUILD_MAC
  203.     FW_CPoint endPoint = ((FW_CLineShapeRep*)GetRep())->GetLineEnd();
  204.     FW_CPoint startPoint = ((FW_CLineShapeRep*)GetRep())->GetLineStart();
  205.     FW_SPlatformPoint start = startPoint;
  206.     FW_SPlatformPoint end = endPoint;
  207.     short pen = 1;
  208.  
  209.     ::OpenRgn();
  210.     
  211.     if (endPoint.x < startPoint.x)
  212.     {
  213.         if (endPoint.y < startPoint.y)
  214.         {            
  215.             ::MoveTo(start.h + pen, start.v);
  216.             ::LineTo(end.h + pen, end.v);
  217.             ::Line(-pen, 0);            
  218.             ::Line(0, pen);
  219.             ::LineTo(start.h, start.v + pen);            
  220.             ::Line(-pen, 0);
  221.             ::Line(0, -pen);
  222.         }
  223.         else if (endPoint.y > startPoint.y)
  224.         {
  225.             ::MakeLineRgn(start, end, pen);        
  226.         }
  227.         else
  228.         {
  229.             ::MakeLineRgn(start, end, pen);        
  230.         }
  231.     }
  232.     else if (endPoint.x > startPoint.x)
  233.     {
  234.         if (endPoint.y < startPoint.y)
  235.         {
  236.             ::MakeLineRgn(start, end, pen);        
  237.         }
  238.         else if (endPoint.y > startPoint.y)
  239.         {
  240.             ::MoveTo(start.h, start.v);
  241.             ::Line(pen, 0);
  242.             ::LineTo(end.h + pen, end.v);
  243.             ::Line(0, pen);
  244.             ::Line(-pen, 0);
  245.             ::LineTo(start.h, start.v + pen);
  246.             ::Line(0, -pen);
  247.         }
  248.         else
  249.         {
  250.             ::MakeLineRgn(start, end, pen);        
  251.         }
  252.     }
  253.     else
  254.     {
  255.         if (endPoint.y < startPoint.y)
  256.         {
  257.             ::MakeLineRgn(start, end, pen);        
  258.         }
  259.         else if (endPoint.y > startPoint.y)
  260.         {
  261.             ::MakeLineRgn(start, end, pen);        
  262.         }
  263.         else
  264.         {        
  265.             ::MoveTo(start.h, start.v);
  266.             ::Line(pen, 0);
  267.             ::Line(0, pen);
  268.             ::Line(-pen, 0);
  269.             ::Line(0, -pen);            
  270.         }
  271.     }
  272.     FW_PlatformRegion rgn = ::NewRgn();
  273.     ::CloseRgn(rgn);
  274.     
  275.     XMPShape* xmpShape = ::NewXMPShape(rgn);
  276.     FW_CRegionShape regionShape(xmpShape);
  277.     return regionShape;
  278. #endif
  279. #ifdef FW_BUILD_WIN
  280.     NotYetImplemted();
  281. #endif
  282. }
  283.  
  284. //==============================================================================
  285. //    •• class FW_CLineShapeRep
  286. //==============================================================================
  287.  
  288. //------------------------------------------------------------------------------
  289. //    • FW_CLineShapeRep::FW_CLineShapeRep
  290. //------------------------------------------------------------------------------
  291.  
  292. FW_CLineShapeRep::FW_CLineShapeRep() :
  293.     FW_CShapeRep(gGraphicGlobales.gLine),
  294.     fStart(FW_kZeroPoint),
  295.     fEnd(FW_kZeroPoint)
  296. {
  297. }
  298.  
  299. //------------------------------------------------------------------------------
  300. //    • FW_CLineShapeRep::FW_CLineShapeRep
  301. //------------------------------------------------------------------------------
  302.  
  303. FW_CLineShapeRep::FW_CLineShapeRep(const FW_CPoint& start, const FW_CPoint& end) :
  304.     FW_CShapeRep(gGraphicGlobales.gLine),
  305.     fStart(start),
  306.     fEnd(end)
  307. {
  308. }
  309.  
  310. //------------------------------------------------------------------------------
  311. //    • FW_CLineShapeRep::~FW_CLineShapeRep
  312. //------------------------------------------------------------------------------
  313.  
  314. FW_CLineShapeRep::~FW_CLineShapeRep()
  315. {
  316. }
  317.  
  318. //------------------------------------------------------------------------------
  319. //    • FW_CLineShapeRep::Draw
  320. //------------------------------------------------------------------------------
  321.  
  322. void FW_CLineShapeRep::Draw(FW_CGraphicContext* graphicContext)
  323. {
  324.     FW_ShapeFills shapeFill = GetShapeFill();
  325.  
  326.     if (shapeFill == FW_kNullShape)
  327.         return;
  328.     
  329.     graphicContext->SelectInkAndStyle(GetShapeInk(), GetShapeStyle(), FW_kGeometricShape, shapeFill);
  330.  
  331.     FW_SPlatformPoint start = graphicContext->AsPlatformPoint(fStart);
  332.     FW_SPlatformPoint end = graphicContext->AsPlatformPoint(fEnd);
  333.     
  334. #ifdef FW_BUILD_MAC
  335.     ::MoveTo(start.h, start.v);
  336.     ::LineTo(end.h, end.v);
  337. #endif
  338. }
  339.  
  340. //------------------------------------------------------------------------------
  341. //    • FW_CLineShapeRep::DrawLine
  342. //------------------------------------------------------------------------------
  343.  
  344. void FW_CLineShapeRep::DrawLine(FW_CGraphicContext* graphicContext,
  345.                                 const FW_CPoint& start,
  346.                                 const FW_CPoint& end)
  347. {
  348.     if (gGraphicGlobales.gLine.fFill == FW_kNullShape)
  349.         return;
  350.  
  351.     graphicContext->SelectInkAndStyle(gGraphicGlobales.gLine.fInk, gGraphicGlobales.gLine.fStyle, FW_kGeometricShape, gGraphicGlobales.gLine.fFill);
  352.  
  353.     FW_SPlatformPoint qdStart = graphicContext->AsPlatformPoint(start);
  354.     FW_SPlatformPoint qdEnd = graphicContext->AsPlatformPoint(end);
  355.     
  356. #ifdef FW_BUILD_MAC
  357.     ::MoveTo(qdStart.h, qdStart.v);
  358.     ::LineTo(qdEnd.h, qdEnd.v);
  359. #endif
  360. }
  361.  
  362. //------------------------------------------------------------------------------
  363. //    • FW_CLineShapeRep::GetShapeBounds
  364. //------------------------------------------------------------------------------
  365.  
  366. FW_CRect FW_CLineShapeRep::GetShapeBounds() const
  367. {
  368.     FW_CRect bounds;
  369.     
  370.     XMPCoordinate penSize = GetShapeStyle()->GetPenSize();
  371.     
  372.     bounds.Set(fStart.x, fStart.y, fEnd.x, fEnd.y);
  373.     bounds.Sort();
  374.     bounds.right += penSize;
  375.     bounds.bottom += penSize;
  376.     
  377.     return bounds;
  378. }
  379.  
  380. //------------------------------------------------------------------------------
  381. //    • FW_CLineShapeRep::Transform
  382. //------------------------------------------------------------------------------
  383.  
  384. void FW_CLineShapeRep::Transform(XMPTransform* transform)
  385. {
  386.     fStart = transform->TransformPoint(fStart);
  387.     fEnd = transform->TransformPoint(fEnd);
  388. }
  389.  
  390. //------------------------------------------------------------------------------
  391. //    • FW_CLineShapeRep::InverseTransform
  392. //------------------------------------------------------------------------------
  393.  
  394. void FW_CLineShapeRep::InverseTransform(XMPTransform* transform)
  395. {
  396.     fStart = transform->InvertPoint(fStart);
  397.     fEnd = transform->InvertPoint(fEnd);
  398. }
  399.  
  400. //------------------------------------------------------------------------------
  401. //    • FW_CLineShapeRep::MoveShape
  402. //------------------------------------------------------------------------------
  403.  
  404. void FW_CLineShapeRep::MoveShape(XMPCoordinate deltaX, XMPCoordinate deltaY)
  405. {
  406.     fStart.x += deltaX;
  407.     fStart.y += deltaY;
  408.     fEnd.x += deltaX;
  409.     fEnd.y += deltaY;
  410. }
  411.  
  412. //------------------------------------------------------------------------------
  413. //    • FW_CLineShapeRep::MoveShapeTo
  414. //------------------------------------------------------------------------------
  415.  
  416. void FW_CLineShapeRep::MoveShapeTo(XMPCoordinate x, XMPCoordinate y)
  417. {
  418.     fEnd.x += x - fStart.x;
  419.     fEnd.y += y - fStart.y;
  420.     fStart.x = x;
  421.     fStart.y = y;
  422. }
  423.  
  424. //------------------------------------------------------------------------------
  425. //    • FW_CLineShapeRep::Copy
  426. //------------------------------------------------------------------------------
  427.  
  428. FW_CLineShape FW_CLineShapeRep::Copy() const
  429. {
  430.     FW_CLineShape line(fStart, fEnd);
  431.     return line;
  432. }
  433.  
  434. //------------------------------------------------------------------------------
  435. //    • FW_CLineShapeRep::SetAsDefault
  436. //------------------------------------------------------------------------------
  437.  
  438. void FW_CLineShapeRep::SetAsDefault() const
  439. {
  440.     SetDefaultProperties(gGraphicGlobales.gLine);
  441. }
  442.  
  443. //------------------------------------------------------------------------------
  444. //    • FW_CLineShapeRep::HitTest
  445. //------------------------------------------------------------------------------
  446.  
  447. FW_HitTestPart FW_CLineShapeRep::HitTest(const FW_CPoint& test) const
  448. {
  449.     return FW_kOutside;
  450. }
  451.  
  452. //----------------------------------------------------------------------------------------
  453. //    • FW_CLineShapeRep::Flatten
  454. //----------------------------------------------------------------------------------------
  455.  
  456. void FW_CLineShapeRep::Flatten(FW_CWritableStream& stream)
  457. {
  458.     fStart.Flatten(stream);
  459.     fEnd.Flatten(stream);
  460. }
  461.  
  462. //----------------------------------------------------------------------------------------
  463. //    • FW_CLineShapeRep::Unflatten
  464. //----------------------------------------------------------------------------------------
  465.  
  466. void FW_CLineShapeRep::Unflatten(FW_CReadableStream& stream)
  467. {
  468.     fStart.Unflatten(stream);
  469.     fEnd.Unflatten(stream);
  470. }
  471.